package com.cxs.videoplayer.util;

public class DateUtil {
    // 1s = 1000ms
    private static final int One_Sec_Ms = 1000;
    // 1min = 60s
    private static final int One_Min_Sec = 60;
    // 1h = 60min
    private static final int One_Hour_Min = 60;

    private static final String Format = "%02d";

    public static String msToTimeString(int ms) {
        int seconds = ms/ One_Sec_Ms;    // 总秒数

        int minutes = seconds / One_Min_Sec;  // 总分钟 = 总秒数 / 60
        int second = seconds % One_Min_Sec;   // 剩余秒数 = 总秒数 % 60

        int hour = minutes / One_Hour_Min;    // 总小时数 = 总分钟 / 60
        int minute = minutes % One_Hour_Min;  // 剩余分钟 = 总分中 % 60

        String formatHour = String.format(Format, hour);
        String formatMin = String.format(Format, minute);
        String formatSec = String.format(Format, second);

        if (hour > 0) {
            return formatHour + ":" + formatMin + ":" + formatSec;
        } else {
            return formatMin + ":" + formatSec;
        }
    }
}
